package com.fantasy.demo1.controller;

import com.fantasy.demo1.component.LibraryProperties;
import com.fantasy.demo1.entity.PersonDest;
import com.fantasy.demo1.entity.PersonInfo;
import com.fantasy.demo1.entity.PersonSource;
import com.fantasy.demo1.schedule.ScheduleTest;
import org.springframework.beans.BeanUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 返回一个html页面
 */
@RestController
@RequestMapping("/api")
public class TestController {

    @Resource
    private LibraryProperties library;

    @Resource
    private ScheduleTest scheduleTest;

    /**
     * 测试获取配置信息
     * @return
     */
    @GetMapping("/props")
    public String getProperties() {
        String location = library.getLocation();
        return location;
    }

    @GetMapping("/bean")
    public void TestSpringBeanUtils() {
        // 用于单独测试
        PersonSource personSource = new PersonSource(1, "fantasy", "123456", 21);
        PersonDest personDest = new PersonDest();
        BeanUtils.copyProperties(personSource, personDest);
        System.out.println("persondest" + personDest);
    }

    @PostMapping("/personinfo")
    public ResponseEntity<PersonInfo> getPersonInfo(@RequestBody @Valid PersonInfo personInfo) {
       return ResponseEntity.ok().body(personInfo);
    }


}
